<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        $this->success('请求成功');
    }
    public function getJssdk()
    {
        $url = $this->request->param('url');
        $platform = $this->request->post("platform",'wechat');
        $config = get_addon_config('third');
        $app = new \addons\third\library\Application($config);
        //通过code换access_token和绑定会员
        $result = $app->wechat->getJssdk($url);
        $this->success('获取成功',$result);
    }

    #获取省
    public function getShen()
    {
        $keywods = $this->request->param('keywords');
        $where = ['status'=>1];
        if(!empty($keywods)){
            $where['name'] = ['like','%'.$keywods.'%'];
        }
        $list = DB('qun_cate')->order('weigh desc')->where($where)->select();
        foreach ($list as &$v){
            $v['image'] = cdnurl($v['image']);
        }
        $this->success('获取成功',$list);
    }

    # 获取群
    public function getQun()
    {
        $cid = $this->request->param('cid');
        $where = ['status'=>1,'cid'=>$cid];
//        if(!empty($keywods)){
//            $where['name'] = ['like','%'.$keywods.'%'];
//        }
        $list = DB('qun_list')->order('weigh desc')->where($where)->select();
        foreach ($list as &$v){
            $v['image'] = cdnurl($v['image']);
        }
        $this->success('获取成功',$list);
    }

    # 获取客服
    public function getKefu()
    {
        $list = DB('kefu')->order('weigh desc')->where('status',1)->select();
        foreach ($list as &$v){
            $v['image'] = cdnurl($v['image']);
            $v['wechat_image'] = cdnurl($v['wechat_image']);
        }
        $this->success('获取成功',$list);
    }
    public function getConfig(){
        $poster = Db::name("config")->where(['name'=>'poster'])->value('value');
        $re_data['poster'] = cdnurl($poster,true);
        $this->success("配置项",$re_data);
    }

}
